/**
 * 登陆
 * @authors Your Name (you@example.org)
 * @date    2016-11-02 11:00:37
 * @version $Id$
 */
define(['app'],function(app){//依赖app.js 模块
    app.controller('LoginCtrl',['$scope','$rootScope','$filter','$location','systemService','localStorageService',
        function($scope,$rootScope,$filter,$location,systemService,localStorageService){

        /**
         * 登陆
         * @return {[void]}
         */
        $scope.loginFun = function(){
        	//验证账户名 密码是否为空
            if($scope.security.usercode === ''){
                alert("请输入登录账号！");
                return;
            }
            if($scope.security.password === ''){
                alert("请输入登录密码！");
                return;
            }
            //与后台链接的登陆方法
        	systemService.loginFun($scope.security.usercode,$scope.security.password).then(
                function(response){
                    if(response.status == 200){
                        $rootScope.user.name = response.name;
                        $rootScope.user.token = response.token;
                        localStorageService.setName(response.name);
                        localStorageService.setToken(response.token);
                    }else{
                        alert("登录失败");
                    }
                },
                function(code){
                }
            );
        };
        
        //初始化函数
        var init = function(){
            $scope.security = {
                usercode: "",
                password: ""
            };
        };
        init();
    }]);
});

